package com.sxf.core.record.threadlocal;

import com.sxf.core.record.entity.SourceRecord;

/**
 * @description:
 * @author: zhangyb@ccccit.com.cn
 * @date: 2021年5月14日 上午11:33:10
 */
public class RecordDataThreadLocal {

	private static final ThreadLocal<SourceRecord> RECORD_TRHEAD_LOCAL = new ThreadLocal<SourceRecord>() {
		@Override
		protected SourceRecord initialValue() {
			return new SourceRecord();
		}
	};

	public static SourceRecord set(String url, String header) {
		RECORD_TRHEAD_LOCAL.get().setUrl(url);
		RECORD_TRHEAD_LOCAL.get().setHeader(header);
		return RECORD_TRHEAD_LOCAL.get();
	}

	public static SourceRecord setReq(String request) {
		RECORD_TRHEAD_LOCAL.get().setRequest(request);
		return RECORD_TRHEAD_LOCAL.get();
	}

	public static SourceRecord setRes(String response, Integer success) {
		RECORD_TRHEAD_LOCAL.get().setResponse(response);
		RECORD_TRHEAD_LOCAL.get().setSuccess(success);
		return RECORD_TRHEAD_LOCAL.get();
	}
	
	public static SourceRecord setResult(String req, String res, Integer success) {
		RECORD_TRHEAD_LOCAL.get().setRequest(req);
		RECORD_TRHEAD_LOCAL.get().setResponse(res);
		RECORD_TRHEAD_LOCAL.get().setSuccess(success);
		return RECORD_TRHEAD_LOCAL.get();
	}

	public static SourceRecord get() {
		return RECORD_TRHEAD_LOCAL.get();
	}

	public static void remove() {
		RECORD_TRHEAD_LOCAL.remove();
	}
}
